package com.ruoyi.shop.controller;

import java.util.List;
import java.io.IOException;
import javax.servlet.http.HttpServletResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.log.annotation.Log;
import com.ruoyi.common.log.enums.BusinessType;
import com.ruoyi.common.security.annotation.RequiresPermissions;
import com.ruoyi.shop.domain.Billing;
import com.ruoyi.shop.service.IBillingService;
import com.ruoyi.common.core.web.controller.BaseController;
import com.ruoyi.common.core.web.domain.AjaxResult;
import com.ruoyi.common.core.utils.poi.ExcelUtil;
import com.ruoyi.common.core.web.page.TableDataInfo;

/**
 * 商家对账Controller
 * 

 * @date 2023-07-24
 */
@RestController
@RequestMapping("/billing")
public class BillingController extends BaseController
{
    @Autowired
    private IBillingService billingService;

    /**
     * 查询商家对账列表
     */
    @RequiresPermissions("shop:billing:list")
    @GetMapping("/list")
    public TableDataInfo list(Billing billing)
    {
        startPage();
        List<Billing> list = billingService.selectBillingList(billing);
        return getDataTable(list);
    }

    /**
     * 导出商家对账列表
     */
    @RequiresPermissions("shop:billing:export")
    @Log(title = "商家对账", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, Billing billing)
    {
        List<Billing> list = billingService.selectBillingList(billing);
        ExcelUtil<Billing> util = new ExcelUtil<Billing>(Billing.class);
        util.exportExcel(response, list, "商家对账数据");
    }

    /**
     * 获取商家对账详细信息
     */
    @RequiresPermissions("shop:billing:query")
    @GetMapping(value = "/{billingId}")
    public AjaxResult getInfo(@PathVariable("billingId") Long billingId)
    {
        return success(billingService.selectBillingByBillingId(billingId));
    }

    /**
     * 新增商家对账
     */
    @RequiresPermissions("shop:billing:add")
    @Log(title = "商家对账", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody Billing billing)
    {
        return toAjax(billingService.insertBilling(billing));
    }

    /**
     * 修改商家对账
     */
    @RequiresPermissions("shop:billing:edit")
    @Log(title = "商家对账", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody Billing billing)
    {
        return toAjax(billingService.updateBilling(billing));
    }

    /**
     * 删除商家对账
     */
    @RequiresPermissions("shop:billing:remove")
    @Log(title = "商家对账", businessType = BusinessType.DELETE)
	@DeleteMapping("/{billingIds}")
    public AjaxResult remove(@PathVariable Long[] billingIds)
    {
        return toAjax(billingService.deleteBillingByBillingIds(billingIds));
    }
}
